/**
 * io_stream.h
 *
 *  Created on: 2019-09-05
 *      Author: chenshisheng
 */

#ifndef STREAM_IO_STREAM_H_
#define STREAM_IO_STREAM_H_

#include "main.h"
#include "stream/mem_stream.h"

typedef struct
{
    Stream_t stream;
    MemStream_t rbuf, tbuf;
    Stream_Tx_t tx;
    const Stream_t *bridge;
    int userData;
}IoStream_t;

int IoStream_Init(
        IoStream_t *is,
        void *rxBuf,
        unsigned int rxBufSize,
        void *txBuf,
        unsigned int txBufSize,
        Stream_Tx_t tx,
        int userData);

int IoStream_InitWithoutBuffer(IoStream_t *is, Stream_Put_t put, Stream_Get_t get, Stream_Flush_t flush, int userData);
int IoStream_OnRx(IoStream_t *is, const void *data, unsigned int size);

static inline void IoStream_DeInit(IoStream_t *is)
{
    Stream_DeInit(& is->stream);
}

#endif /* STREAM_IO_STREAM_H_ */
